package com.timguan.render.dao.manager.cms;

import com.timguan.render.dao.domain.cms.CmsTopicDO;
import com.timguan.render.dao.domain.cms.CmsTopicDOExample;
import com.timguan.render.dao.persistence.cms.CmsTopicDOMapper;
import com.timguan.render.dao.persistence.cms.CmsTopicDOMapperExt;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * Created by guankaiqiang on 2015/3/22.
 */
public class CmsTopicManagerImpl {
    @Resource
    private CmsTopicDOMapper cmsTopicDOMapper;
    @Resource
    private CmsTopicDOMapperExt cmsTopicDOMapperExt;
    public int insert(CmsTopicDO record) {
        int id = 0;
        if (record == null) {
            return id;
        }
        Date now = new Date();
        record.setGmtCreate(now);
        record.setGmtModified(now);
        record.setIsDelete(0);
        cmsTopicDOMapper.insert(record);
        return record != null ? record.getId() : 0;
    }

    public int countByExample(CmsTopicDOExample condition) {
        int count = 0;
        if (condition == null) {
            return count;
        }
        count = cmsTopicDOMapper.countByExample(condition);
        return count;
    }

    public List<CmsTopicDO> selectByExample(CmsTopicDOExample condition) {
        List<CmsTopicDO> cmsTopicDOs = null;
        if (condition == null) {
            return cmsTopicDOs;
        }
        cmsTopicDOs = cmsTopicDOMapper.selectByExample(condition);
        return cmsTopicDOs;
    }
    public List<Integer> selectActivityIdsByExample(CmsTopicDOExample condition) {
        if (condition == null) {
            return null;
        }
        condition.createCriteria().andIsDeleteEqualTo(0);
        return cmsTopicDOMapperExt.selectActivityIdsByExample(condition);
    }

    public CmsTopicDO selectByPrimaryKey(int topicId) {
        return cmsTopicDOMapper.selectByPrimaryKey(topicId);
    }

    public int updateByPrimaryKeySelective(CmsTopicDO record) {
        int count = 0;
        if (record == null) {
            return count;
        }
        Date now = new Date();
        record.setGmtModified(now);
        count = cmsTopicDOMapper.updateByPrimaryKeySelective(record);
        return count;
    }
}
